#ifndef TCP_SERVER_CURRENTTHREAD_H
#define TCP_SERVER_CURRENTTHREAD_H

#include <cstdint>
#include <cstring>  // memset
#include <string>

namespace CurrentThread {
    extern __thread int cacheTid_;
    extern __thread char t_tidString[32];
    extern __thread int t_tidStringLength;
    extern __thread const char *t_threadName;

    void cacheTid();

    inline int getTid() {
        if (cacheTid_ == 0) cacheTid();
        return cacheTid_;
    }

    inline const char *tidString() // for logging
    {
        return t_tidString;
    }

    inline int tidStringLength() // for logging
    {
        return t_tidStringLength;
    }

    inline const char *name() {
        return t_threadName;
    }

    bool isMainThread();
}


#endif //TCP_SERVER_CURRENTTHREAD_H
